Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

716
Visualizações
"There was an error parsing the body" error on requesting endpoint in FastAPI

I have implemented a endpoint in FastAPI and I am testing it from Postman. But whenever I send request I get this error "There was an error parsing the body", while searching for the error I found a solution somewhere that I need to have python-multipart installed, this package is already installed but I am still facing this error. Following is my code:

@router.put('/user')
def update_user(user_data: dict):
    from crain.uma import update_user
    user_id = user_data['id']
    update_user(user_id, user_data)
    return {"message": "DONE"}

The endpoint except a dict like this:

user_data =    {
      "username":"admin",
      "id":"2d06aa3b-c25a-4499-948a-86341ac4adc5",
      "email":null,
      "firstName":"admin",
      "lastName":"admin",
      "createdTimestamp":1638268009973
   },

enter image description here enter image description here

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

in postman switch to raw data (currently you are in form-data).
then insert your desired payload:

{
      "username":"admin",
      "id":"2d06aa3b-c25a-4499-948a-86341ac4adc5",
      "email":null,
      "firstName":"admin",
      "lastName":"admin",
      "createdTimestamp":1638268009973
}

and fire the request.

BTW, when you say

The endpoint except a dict like this:

user_data = {  
      "username":"admin",  
      "id":"2d06aa3b-c25a-4499-948a-86341ac4adc5",  
      "email":null,  
      "firstName":"admin",  
      "lastName":"admin",  
      "createdTimestamp":1638268009973
},

you actually mean the endpoint expect only the dictionary part, because user_data is simply a variable name in your python code, completely unrelated to any request configuration.
the reason i specify it is because you wrote it as a key you the postman's request form-data (the picture you uploaded)

over 4 years ago · Santiago Trujillo Relatório

0

In short, your endpoint expects JSON data, but your client sends form-data instead. Thus, when sending the request select raw data instead.

Additioanlly, I would highly sugget to use Pydantic models for sending JSON data, as described in the documentation. Thus, you can make use of the data validation that Pydantic offers. You can even use EmailStr type for validating email inputs (requires email-validator to be installed, as described in the documentation). Example below:

from pydantic import BaseModel, EmailStr
from datetime import datetime
class User(BaseModel):
    username: str
    id: str
    email: EmailStr = None
    firstName: str
    lastName: str
    createdTimestamp: datetime
    
@app.put('/user')
def update_user(user_data: User):
    from crain.uma import update_user
    user_data = user_data.dict()
    user_id = user_data['id']
    update_user(user_id, user_data)
    return {"message": "DONE"}

JSON payload should look like:

{
    "username":"admin",
    "id":"2d06aa3b-c25a-4499-948a-86341ac4adc5",
    "email":null,
    "firstName":"admin",
    "lastName":"admin",
    "createdTimestamp":1638268009973
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda